<?php

class Upload extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
        $this->load->helper(array('form', 'url'));
        $this->load->model('up_model');
        $this->load->model('news_model');
        $this->load->helper('url');
    }

    public function index()
    {
        $this->load->view('upload_form', array('error' => ' ' ));
    }

    public function do_upload()
    {
       // echo "a";
        ini_set('date.timezone','Asia/Shanghai');//调整时区
        $config['upload_path']      = '/data/app/album.wesnaps.com/attachment/enread/';
        $config['allowed_types']    = 'gif|jpg|png';
        $config['max_size']     = 1024;
        $config['max_width']        = 1024;
        $config['max_height']       = 768;

        $this->load->library('upload', $config);
        $this->upload->initialize($config);
        $id=$this->input->post('id');
        $weid=$this->input->post('select[0]');
        $us_id=$this->input->post('select2[0]');
        $title=$this->input->post('ftitle');
        $author=$this->input->post('fauthor');
        $img_desc=$this->input->post('fdesc');
        $music_url=$this->input->post('musicurl');
        $img_path=$this->input->post('img_path');
        
        $up = array(
                    'id' => $id,
                    'weid' => $weid,//名字
                    'us_id' => $us_id,
                    'title' =>$title,
                    'author' => $author,
                    'img_desc' => $img_desc,
                    'music_url' => $music_url,
                    'lasttime' => time() 
                );
        if($id==0){
                $up['createtime']=time();            
           }
        $this->upload->do_upload('userfile');
        $data = array('upload_data' => $this->upload->data());
      //  var_dump($data['upload_data']['file_name']);
        if($data['upload_data']['file_name']!=null){
             if ( !$this->upload->do_upload('userfile')){
                 $error = array('error' => $this->upload->display_errors());
                 $this->load->view('upload_form', $error);
                 return ;
             }
            else {
                $up['img_path'] = '/attachment/enread/'.$data['upload_data']['file_name'];
            }
        }
      //  var_dump($img_path);
        $this->up_model->save($up);//上传
        //$dd['arr'] = $this->news_model->ims_account_wechats();
        //$this->load->view('pages/upload');
    }
}
?>